//
//  SetingViewController.swift
//  BaseSwift
//
//  Created by gh on 2019/10/9.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit
import EasyNavigation


class SetingViewController: UIViewController {

    let lab = UILabel()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.navigationView.setTitle("设置")
        self.view.backgroundColor = UIColor.backgroundColor
        
        let aboutBtn = UIButton()
        view.addSubview(aboutBtn)
        aboutBtn.backgroundColor = UIColor.white
        aboutBtn.setTitle("关于我们", for: .normal)
        aboutBtn.addTarget(self, action: #selector(aboutClick), for: .touchUpInside)
        aboutBtn.titleLabel?.font = UIFont.commonFont
        aboutBtn.setTitleColor(UIColor.textTitleColor, for: .normal)
        aboutBtn.setImage(UIImage(named: "向右"), for: .normal)
        let _ = aboutBtn.sd_layout()?.widthRatioToView(view,1)!.heightIs(50)!.topSpaceToView(view,HT_StatusBarAndNavigationBarHeight+16)!
        let _ = aboutBtn.titleLabel?.sd_layout()?.leftSpaceToView(aboutBtn,16)
        let _ = aboutBtn.imageView?.sd_layout()?.widthIs(16)!.heightIs(16)!.rightSpaceToView(aboutBtn,16)!.centerYEqualToView(aboutBtn)
        
        let user0Btn = UIButton()
        view.addSubview(user0Btn)
        user0Btn.backgroundColor = UIColor.white
        user0Btn.setTitle("用户服务协议", for: .normal)
        user0Btn.addTarget(self, action: #selector(userServiceClick), for: .touchUpInside)
        user0Btn.titleLabel?.font = UIFont.commonFont
        user0Btn.setTitleColor(UIColor.textTitleColor, for: .normal)
        user0Btn.setImage(UIImage(named: "向右"), for: .normal)
        let _ = user0Btn.sd_layout()?.widthRatioToView(view,1)!.heightIs(50)!.topSpaceToView(aboutBtn,1)!
        let _ = user0Btn.titleLabel?.sd_layout()?.leftSpaceToView(user0Btn,16)
        let _ = user0Btn.imageView?.sd_layout()?.widthIs(16)!.heightIs(16)!.rightSpaceToView(user0Btn,16)!.centerYEqualToView(user0Btn)
        
        let user1Btn = UIButton()
        view.addSubview(user1Btn)
        user1Btn.backgroundColor = UIColor.white
        user1Btn.setTitle("用户隐私协议", for: .normal)
        user1Btn.addTarget(self, action: #selector(userPrivateClick), for: .touchUpInside)
        user1Btn.titleLabel?.font = UIFont.commonFont
        user1Btn.setTitleColor(UIColor.textTitleColor, for: .normal)
        user1Btn.setImage(UIImage(named: "向右"), for: .normal)
        let _ = user1Btn.sd_layout()?.widthRatioToView(view,1)!.heightIs(50)!.topSpaceToView(user0Btn,1)!
        let _ = user1Btn.titleLabel?.sd_layout()?.leftSpaceToView(user1Btn,16)
        let _ = user1Btn.imageView?.sd_layout()?.widthIs(16)!.heightIs(16)!.rightSpaceToView(user1Btn,16)!.centerYEqualToView(user1Btn)
        
        let imgCache = SDImageCache.shared
        let size = String(format: "缓存大小%.2fKB", imgCache.totalDiskSize()/1024)
        
        let clearBtn = UIButton()
        view.addSubview(clearBtn)
        clearBtn.backgroundColor = UIColor.white
        clearBtn.setTitle("清除缓存", for: .normal)
        clearBtn.addTarget(self, action: #selector(clearClick), for: .touchUpInside)
        clearBtn.titleLabel?.font = UIFont.commonFont
        clearBtn.setTitleColor(UIColor.textTitleColor, for: .normal)
        clearBtn.setImage(UIImage(named: "向右"), for: .normal)
        let _ = clearBtn.sd_layout()?.widthRatioToView(view,1)!.heightIs(50)!.topSpaceToView(user1Btn,1)!
        let _ = clearBtn.titleLabel?.sd_layout()?.leftSpaceToView(clearBtn,16)
        let _ = clearBtn.imageView?.sd_layout()?.widthIs(16)!.heightIs(16)!.rightSpaceToView(clearBtn,16)!.centerYEqualToView(clearBtn)
        clearBtn.addSubview(lab)
        lab.text = size
        lab.font = UIFont.commonFont
        lab.textAlignment = .right
        lab.textColor = UIColor.textTitleColor
        let _ = lab.sd_layout()?.heightIs(20)!.centerYEqualToView(clearBtn)!.rightSpaceToView(clearBtn,55)
        lab.setSingleLineAutoResizeWithMaxWidth(235)
        
        let logoutBtn = UIButton()
        view.addSubview(logoutBtn)
        logoutBtn.backgroundColor = UIColor.white
        logoutBtn.setTitle("退出", for: .normal)
        logoutBtn.addTarget(self, action: #selector(logoutClick), for: .touchUpInside)
        logoutBtn.titleLabel?.font = UIFont.commonFont
        logoutBtn.setTitleColor(UIColor.btnMainColor, for: .normal)
        let _ = logoutBtn.sd_layout()?.widthRatioToView(view,1)!.heightIs(50)!.topSpaceToView(clearBtn,16)!
        
    }
    @objc func userServiceClick(){
        
        let webvc = WebViewController()
        webvc.isWord = true
        webvc.myTitle = "好去处用户服务协议"
        let url = Bundle.main.path(forResource: "user_service", ofType: "doc")
        webvc.url = url!
        PUSH(from: self, to: webvc)
        
    }
    @objc func userPrivateClick(){
        
        let webvc = WebViewController()
        webvc.isWord = true
        webvc.myTitle = "好去处用户隐私协议"
        let url = Bundle.main.path(forResource: "user_private", ofType: "docx")
        webvc.url = url!
        PUSH(from: self, to: webvc)
        
    }
    @objc func aboutClick(){
        
        let webvc = WebViewController()
        webvc.isWord = true
        webvc.myTitle = "关于我们"
        let url = Bundle.main.path(forResource: "关于", ofType: "doc")
        webvc.url = url!
        PUSH(from: self, to: webvc)
        
    }
    @objc func clearClick(){
        
        SDImageCache.shared.clearDisk {
            
            ToastUtil.show(msg: "清除成功")
            self.lab.text = "缓存大小0M";
        }
        
    }
    @objc func logoutClick(){
        
    
        API.logout(params: [:]) { (result) in
            

        }
        SPUtil.init().token = ""
        ALNetHTTPCommonConfig.appToken = ""
        SPUtil.init().leaguerId = ""
        SPUtil.init().mobile = ""
        SPUtil.init().headImg = ""
        SPUtil.init().sex = ""
        SPUtil.init().birthDay = ""
        SPUtil.init().nickName = ""
        SPUtil.init().loginStatus = 0
        APP.window?.rootViewController = EasyNavigationController(rootViewController: LoginViewController())

    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
